package com.apes.hr.recruit.service;

import com.apes.framework.api.DomainService;
import com.apes.framework.jpa.spec.JpaDsl;
import com.apes.framework.plugin.esb.api.SimpleRequest;
import com.apes.hr.recruit.model.RecruitChannel;

import com.apes.hr.recruit.repository.RecruitChannelRepository;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 功能：招聘渠道
 *
 * @author HuJianLin
 * @create 2018-04-28 14:35
 */
@Service("hrRecruitChannelService")
public class RecruitChannelService extends DomainService {
    @Autowired
    public RecruitChannelRepository recruitChannelRepository;

    public RecruitChannel saveHttp(SimpleRequest request) {
        RecruitChannel recruitChannel = request.getO(RecruitChannel.class);
        return save(recruitChannel);
    }

    public RecruitChannel save(RecruitChannel recruitChannel) {
        return recruitChannelRepository.saveAndFlush(recruitChannel);
    }

    public String delete(SimpleRequest request){
        RecruitChannel recruitChannel = request.getO(RecruitChannel.class);
        recruitChannelRepository.delete(recruitChannel);
        return "删除成功";
    }

    public Page<RecruitChannel> findAll(SimpleRequest request) {
        List<Map> filters = request.get("condition");
        Sort sort = new Sort(Sort.Direction.DESC, "id");
        return recruitChannelRepository.findAll(JpaDsl.toCriteria(filters), PageRequest.of(request.get("page"), request.get("size"), sort));
    }


    public RecruitChannel findOne(String id) {
        return recruitChannelRepository.findOne(id);
    }
}
